import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index'
Vue.use(Router)

const router = new Router({
  mode: "hash",
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/pages/home.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/gallery',
      name: 'gallery',
      component: () => import('@/pages/gallery.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/team',
      name: 'team',
      component: () => import('@/pages/team.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/team1',
      name: 'team1',
      component: () => import('@/pages/team1'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/team2',
      name: 'team2',
      component: () => import('@/pages/team2'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/team3',
      name: 'team3',
      component: () => import('@/pages/team3'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/team4',
      name: 'team4',
      component: () => import('@/pages/team4'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/contact',
      name: 'contact',
      component: () => import('@/pages/contact'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/apply',
      name: 'apply',
      component: () => import('@/pages/apply'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/faq',
      name: 'faq',
      component: () => import('@/pages/faq'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/products',
      name: 'products',
      component: () => import('@/pages/booking.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/payment',
      name: 'payment',
      component: () => import('@/pages/payment.vue'),
      meta: {
        nav: '',
        nokeep: true
      },
    },
    {
      path: '/payment/success',
      name: 'paymentSuccess',
      component: () => import('@/pages/paymentSuccess.vue'),
      meta: {
        nav: '',
        nokeep: true
      },
    },
    {
      path: '/order',
      name: 'order',
      component: () => import('@/pages/order.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    },
    {
      path: '/OrderList',
      name: 'OrderList',
      component: () => import('@/pages/orderList.vue')
    },
    {
      path: '/orderInclude',
      name: 'orderInclude',
      component: () => import('@/pages/orderInclude.vue'),
      meta: {
        nav: '',
        nokeep: true
      }
    }
  ],
  // 路由切换后重定向滚动条
  scrollBehavior(to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


router.beforeEach(async (to, from, next) => {
  if (!store.state.banners) {
    await store.dispatch('getBannerList')
  }
  next()
})

export default router
